package Tests;

import Friend.FriendArray;
import Population.*;

public class TestFriends {
	boolean testConclusion = false;
	boolean[] tests = {false,false,false,false,false,false,false,false,false,false,false,false};
	Population p;
	public TestFriends()
	{//Run test
		p = new Population(0);
		
		p.Add(1, 1, -1);
		p.Add(1, 2, -1);
		p.Add(2, 1, -1);
		p.Add(2, 2, -1);
		p.Add(3, 3, -1);
		p.Add(5, 5, -1);
		
		p.get(0).FindNeighbors();
		p.get(1).FindNeighbors();
		p.get(2).FindNeighbors();
		p.get(3).FindNeighbors();
		p.get(4).FindNeighbors();
		p.get(5).FindNeighbors();
		
		//System.out.println(p.Report());
		
		FriendArray friendList = new FriendArray();
		friendList = p.get(0).getFriends();
		//System.out.println("List length: "+friendList.length);
		if(friendList.getLength()==3)
		{
			if(CheckForID(p.get(1).getID()) && CheckForID(p.get(2).getID()) && CheckForID(p.get(3).getID()))
				tests[0] = true;
		}

		
		friendList = p.get(1).getFriends();
		if(friendList.getLength()==3)
		{
			if(CheckForID(p.get(0).getID()) && CheckForID(p.get(2).getID()) && CheckForID(p.get(3).getID()))
				tests[1] = true;
		}

		
		friendList = p.get(2).getFriends();
		if(friendList.getLength()==3)
		{
			if(CheckForID(p.get(1).getID()) && CheckForID(p.get(0).getID()) && CheckForID(p.get(3).getID()))
				tests[2] = true;
		}

		
		friendList = p.get(3).getFriends();
		if(friendList.getLength()==4)
		{
			if(CheckForID(p.get(1).getID()) && CheckForID(p.get(2).getID()) && CheckForID(p.get(0).getID()) && CheckForID(p.get(4).getID()))
				tests[3] = true;
		}

		
		friendList = p.get(4).getFriends();
		if(friendList.getLength()==1)
		{
			if(CheckForID(p.get(3).getID()))
			{
				tests[4] = true;
			}
		}
		
		friendList = p.get(5).getFriends();
		if(friendList.getLength()==0)
		{
				tests[5] = true;
		}
		
		//ReportFriends();
		
		p.get(4).Move(4, 4);

		p.get(0).FindNeighbors();
		p.get(1).FindNeighbors();
		p.get(2).FindNeighbors();
		p.get(3).FindNeighbors();
		p.get(4).FindNeighbors();
		p.get(5).FindNeighbors();
		
		friendList = new FriendArray();
		friendList = p.get(0).getFriends();
		//System.out.println("List length: "+friendList.length);
		if(friendList.getLength()==3)
		{
			if(CheckForID(p.get(1).getID()) && CheckForID(p.get(2).getID()) && CheckForID(p.get(3).getID()))
				tests[6] = true;
		}

		
		friendList = p.get(1).getFriends();
		if(friendList.getLength()==3)
		{
			if(CheckForID(p.get(0).getID()) && CheckForID(p.get(2).getID()) && CheckForID(p.get(3).getID()))
				tests[7] = true;
		}

		
		friendList = p.get(2).getFriends();
		if(friendList.getLength()==3)
		{
			if(CheckForID(p.get(1).getID()) && CheckForID(p.get(0).getID()) && CheckForID(p.get(3).getID()))
				tests[8] = true;
		}

		
		friendList = p.get(3).getFriends();
		if(friendList.getLength()==3)
		{
			if(CheckForID(p.get(1).getID()) && CheckForID(p.get(2).getID()) && CheckForID(p.get(0).getID()) && CheckForID(p.get(4).getID()))
				tests[9] = true;
		}

		
		friendList = p.get(4).getFriends();
		if(friendList.getLength()==1)
		{
			if(CheckForID(p.get(5).getID()))
			{
				tests[10] = true;
			}
		}
		
		friendList = p.get(5).getFriends();
		if(friendList.getLength()==1)
		{
			if(CheckForID(p.get(4).getID()))
				tests[11] = true;
		}
		
		
		//ReportFriends();
		if(GetTestsConclusion())
		{
			testConclusion = true;
		}
		
	}
	
	public boolean Test()
	{
		return testConclusion;
	}
	
	public boolean CheckForID(int id)
	{
		for(int i=0; i<p.getLength(); i++)
		{
			if(p.get(i).getID() == id)
				return true;
		}
		return false;
	}
	
	public boolean GetTestsConclusion()
	{
		for(int i=0; i<tests.length; i++)
		{
			if(!tests[i])
				return false;
		}
		if(tests.length > 0)
		{
			return true;
		}
		return false;
	}
	
	public boolean[] getTests()
	{
		return tests;
	}
	
	/*public void ReportFriends()
	{
		for(int i=0; i<p.getLength(); i++)
		{
			System.out.println(i + ": " +p.get(i).ReportFriends());
		}
	}*/
}
